{{- if and .Values.servicereplica.enable ( gt .Values.replicas 1.0 ) }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "spilo-art.fullname" . }}-replica
  labels:
    {{- include "spilo-art.headerLabels" . | nindent 4 }}
    {{- include "spilo-art.baseSelectorLabels" . | nindent 4 }}
  {{- if .Values.servicereplica.annotations }}
  annotations:
    {{- toYaml .Values.servicereplica.annotations | nindent 4 }}
  {{- end}}
spec:
  type: {{ .Values.servicereplica.type }}
  ports:
  - name: {{ .Values.servicereplica.name }}
    port: {{ .Values.servicereplica.port}}
    targetPort: 5432
    {{- if and (eq .Values.servicereplica.type "NodePort") .Values.servicereplica.nodePort }}
    nodePort: {{ .Values.servicereplica.nodePort}}
    {{- end }}
  selector:
    {{- include "spilo-art.selectorLabels" . | nindent 4 }}
    role: replica
{{- end }}